#include "json.h"

#include <iostream>

int main()
{
	json::document doc;
	const char* filename = "./test/pass1.json";
	bool res = doc.load(filename);

	json_type type = doc.type(); //JSON_ARRAY
	bool value0 = doc[5].as_bool(); //true
	const char* value1 = doc.array_first().str(); //"JSON Test Pattern pass1"
	const char* name1 = doc[1].child().name(); //"object with 1 member"
	int value3 = doc[8]("integer").as_int(); //1234567890

	// print 1st level
	using std::cout;
	using std::endl;
	for (json::value v = doc.child(); v; v = v.sibling())
	{
		cout << "type:";
		switch(v.type())
		{
		case JSON_ARRAY:
			cout << "ARRAY ";
			break;;
		case JSON_NULL:
			cout << "NULL ";
			break;
		case JSON_BOOL:
			cout << "BOOL value:" << (v.as_bool() ? "true" : "false");
			break;
		case JSON_FLOAT:
			cout << "FLOAT value:" << v.as_float();
			break;
		case JSON_OBJECT:
			cout << "OBJECT name:" << (v.name() ? v.name() : "unnamed");
			break;
		case JSON_STRING:
			cout << "STRING value:" << v.as_str();
			break;
		case JSON_INT:
			cout << "INT value:" << v.as_int();
			break;
		}
		cout << endl;		
	}

	return 0;
}